<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/commons/taglibs.jsp" %>
<!DOCTYPE HTML>
<html>
  <head>
  <title>${tableBean.tableNameNoDash}列表</title>
  	<script type="text/javascript" src="${r'${ctx}'}/static/js/angular-1.2.19/angular.min.js"></script>
 	<script type="text/javascript" src="${r'${ctx}'}/static/js/angular-1.2.19/ngPagination/ngPagination.js"></script>
  </head>
  <body>
 	<a class="btn-link pull-right"  href="${r'${ctx}'}/${tableBean.tableNameNoDash}/form">添加</a>
 	<div ng-app="${tableBean.tableNameNoDash}_app" ng-controller="${tableBean.tableNameNoDash}_contr">
 	<table class="table table-striped table-bordered table-hover" id="bvaProbWordTagList">
 	<thead><tr>
	 	<#list tableBean.columnBeanList as columnBean>
	 		 <#if !(columnBean.priKey)>
			 	<td>${columnBean.columnComment}</td>
			 </#if>
 		</#list>
 		<td>操作</td>
 	</tr>
 	
 	<tr ng-repeat="bean in  page.content">
 		<#list tableBean.columnBeanList as columnBean>
	 		 <#if !(columnBean.priKey)>
	 		  	<#if ('Date'==columnBean.columnType)>
	 		  			<td>{{bean.${columnBean.columnNameNoDash}|date:'yyyy-MM-dd HH:mm:ss'}}</td>
	 		  		<#else>
			 			<td>{{bean.${columnBean.columnNameNoDash}}}</td>
			 	</#if>
			 </#if>
 		</#list>
 		<td>
	 		<a class="btn btn-link" href="${r'${ctx}'}/${tableBean.tableNameNoDash}/form?id={{bean.id}}">查看</a>
	 		<a class="btn btn-link" ng-click="del(bean.id)">删除</a>
 		</td>
 	</tr>
 	</thead>
 	</table>
 	<ng-pagination total_page="page.totalPages"
                     total_ele="page.totalElements"
                     curr_page="page.number"
                     to_page="toPage"
                     sort='page.sort'
                     slicer="[10,15,20]" />
 	</div>
 	<script type="text/javascript">
 	angular.module('${tableBean.tableNameNoDash}_app',['ngPagination'])
    .controller('${tableBean.tableNameNoDash}_contr',function($scope,getDatas){
            $scope.init={pageSize:10}
            //删除
			$scope.del=function(id){
            	layer.msg('确定删除？', {
            	    time: 0 //不自动关闭
            	    ,btn: ['确定', '取消']
            	    ,yes: function(index){
            		layer.load();
                	getDatas.del(id).success(function(d,s){
                		 $scope.toPage($scope.page.number,$scope.init.pageSize);
                		 layer.close(index);
                    	});
            	    }
        	    	,no:function(index){
        	    		layer.close(index);
            	    	}
            	});
            	
    			}
            //请求数据
            $scope.toPage=function(currPage,size,sort){
              layer.load();
              $scope.init.pageSize=size;
              getDatas.datas(currPage,size,sort).success(function(d,s){
                $scope.page=d;
                if($scope.init.type==1){
                  $scope.init.padding= d.totalElements;
                }
                layer.closeAll('loading');
                if(d.sort){
                  var sort ={};
                  sort[d.sort[0].property]= d.sort[0].direction;
                  $scope.page.sort=sort;
                }
              });
            }
            $scope.toPage(0,$scope.init.pageSize);
    })
    .service("getDatas",function($http,$q){
		//删除
        this.del=function(id){
        	 return ajaxRequest("${r'${ctx}'}/${tableBean.tableNameNoDash}/del",{id:id});
            }
      //获取数据
      this.datas=function(page,size,sort){
        var params={page:page,size:size};
        if(sort){
          for(var k in sort){
            params['sort']=k+','+sort[k];
          }
        }else{
          params['sort']='id,desc';
        }
        return ajaxRequest("${r'${ctx}'}/${tableBean.tableNameNoDash}/pageList",params);
      }

      function ajaxRequest(url,params) {
        return $http.post(url, params, {
          headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
          transformRequest: function (data) {
            return $.param(data);
          }
        })
      }
  });
 	</script>
  </body>
</html>
